// forcetalk.txt
// Liek alknpc, but this character will aprroach and speak with character first time.
// Memory Cells:
//   Cell 0 - If 0, default behavior. If 1, it doesnt fidget.
//   Cell 1 - Number of state when talked to. Plays default text if 0.
//   Cell 2,3 -  Stuff done flag. if it is 0, this character hunts party down
//   Cell 4 - Speaking range. Range pc is within to hunt down. Default to 12.
begincreaturescript;

variables;

short i,target;
short has_greeted = 0;
short speak_range = 12;
short talky = 0;
short follow_on = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Learned Plo");
	set_walk_speed(ME,20);
	
	if (get_memory_cell(4) > 0)
		speak_range = get_memory_cell(4);
	break;

beginstate DEAD_STATE;
break;

beginstate START_STATE;
	if (gf(60,9) >= 5)
		erase_char(ME);
	
	if ((gf(60,9) == 3) && (talky == 0) && (get_nearest_party_char(4) >= 0)) {
		talky = 1;
		talk_no_exit(165);
		}
		
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		set_state(3);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}

	if (get_flag(60,12) == 0) {
		approach_char(ME,pc_num(),1);
		set_state(4);
		}
		else {
			if (follow_on > 0)
				give_char_text_bubble(ME,"Follow.");
			if (dist_to_nav_point(ME,7) > 1)
				approach_nav_point(ME,7,1);
				else follow_on = 0;
			}


break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);
	do_attack();
break;

beginstate 4; // approaching pc
	if (get_flag(60,12) > 0)
		set_state(START_STATE);
	if (get_attitude(ME) >= 10) {
		set_state(START_STATE);
		}
	if ((approach_char(ME,pc_num(),1)) || (dist_to_pc() <= 2)) {
		set_flag(60,12,1);
		follow_on = 1;
		begin_talk_mode(155);
		}
break;


beginstate TALKING_STATE;
	begin_talk_mode(155);
break;